package com.huifer.wgx.controller;

import com.huifer.wgx.model.DetectionPointEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.service.DetectionPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : DetectionPointController </p>
 * <p>Description : 点数据校验结果管理</p>
 *
 * @author huifer
 * @date 2019-03-15
 */
@RestController
@RequestMapping("detection_point")
@Api(tags = "DetectionPointController", description = "点数据校验结果管理")
public class DetectionPointController {

    @Autowired
    private DetectionPointService detectionPointService;

    private CommonResult commonResult = new CommonResult();


    @ApiOperation("保存校验结果")
    @PostMapping("/save")
    public ResponseEntity saveDetectionList(
            @RequestParam("verify_id") Long verifyId,
            @RequestParam("work_id") Long workId,
            @RequestParam("personnel_id") Long personnelId) {
        try {
            List<DetectionPointEntity> list = detectionPointService
                    .createList(verifyId, workId, personnelId);
            return ResponseEntity
                    .ok(commonResult.success(detectionPointService.saveDetectionList(list)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验id查询点数据校验结果")
    @GetMapping("/find_by_verify_id")
    public ResponseEntity findByPersonnelId(
            @RequestParam("personnel_id") Long personnelId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionPointService
                                    .findByPersonnelId(personnelId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验人员名称查询点数据校验结果")
    @GetMapping("/find_by_personnel_name")
    public ResponseEntity findByPersonnelName(
            @RequestParam("personnel_name") String personnelName,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionPointService
                                    .findByPersonnelName(personnelName, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验id查询点数据校验结果")
    @GetMapping("/findByVerifyId")
    public ResponseEntity findByVerifyId(
            @RequestParam("verify_id") Long verifyId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionPointService.findByVerifyId(verifyId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验内容查询点数据校验结果")
    @GetMapping("/find_by_verify_name")
    public ResponseEntity findByVerifyName(
            @RequestParam("verify_name") String verifyName,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionPointService.findByVerifyName(verifyName, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有点数据校验结果")
    @GetMapping("/find_all")
    public ResponseEntity findAllDp(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(detectionPointService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


}
